package com.axend.aerosense.base.utils;

import android.os.Build;
import android.text.TextUtils;
import android.text.format.Time;
import android.util.Log;

import com.axend.aerosense.base.bean.TimeZoneBean;
import com.blankj.utilcode.util.Utils;

import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class SystemUtil {
    public static String EN = "en";
    public static String ZH = "zh";

    public static String getSystemLanguage(){
        String language = EN;
        Locale locale;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            locale = Utils.getApp().getResources().getConfiguration().getLocales().get(0);
        } else {
            locale = Utils.getApp().getResources().getConfiguration().locale;
        }
        if(null != locale && !TextUtils.isEmpty(locale.getLanguage())){
            String tmp = locale.getLanguage();
            if(tmp.contains(ZH) || tmp.contains("ZH")){
                language = ZH;
            }
        }

        return language;
    }

    public static boolean isChineseLanguage(){
        if(SystemUtil.getSystemLanguage().equals(SystemUtil.ZH)){
            return true;
        }else{
            return false;
        }
    }


    public static String getMonth(int index){
        String month = "" + index;
        switch (index){
            case 1:
                month = "January";
                break;
            case 2:
                month = "February";
                break;
            case 3:
                month = "March";
                break;
            case 4:
                month = "April";
                break;
            case 5:
                month = "May";
                break;
            case 6:
                month = "June";
                break;
            case 7:
                month = "July";
                break;
            case 8:
                month = "August";
                break;
            case 9:
                month = "September";
                break;
            case 10:
                month = "October";
                break;
            case 11:
                month = "November";
                break;
            case 12:
                month = "December";
                break;
        }
        return month;
    }

    public static TimeZoneBean getTimeZone(){
        TimeZone timeZone = TimeZone.getDefault();
        String id = timeZone.getID(); //获取时区id，如“Asia/Shanghai”
        int offset = timeZone.getOffset(new Date().getTime());
        int rawOffset = timeZone.getRawOffset(); //获取时差，返回值毫秒
        int roomTimeZone = 0;
        if(offset != rawOffset){
            // 基于时区的偏移量不同,启用夏令时

        }
        roomTimeZone = offset/60/60/1000;

//        Log.e("http:", "offset:" + offset + ", timeZone.getRawOffset()：" + timeZone.getRawOffset());
        return new TimeZoneBean(roomTimeZone >= 0 ? "+" + roomTimeZone:  "" + roomTimeZone, id);
    }

}
